var ns, NVTabBar, trycount = 0;
var app = new Vue({
    el: '#app',
    data: {
        footers: [{
            title: '工作',
            name: 'index_frm',
            is_active: true,
            normal: '../image/index/menu_icon_1.png',
            selected: '../image/index/menu_icon_1_active.png',
            categoryid: 0,
            type: 0
        }, {
            title: '任务',
            name: 'customerservice_win',
            is_active: false,
            normal: '../image/index/menu_icon_2.png',
            selected: '../image/index/menu_icon_2_action.png',
            categoryid: 5,
            type: 1,
            count: 0
        }, {
            title: '消息',
            name: 'home_news_win',
            is_active: false,
            normal: '../image/index/menu_icon_3.png',
            selected: '../image/index/menu_icon_3_action.png',
            categoryid: 0,
            type: 0,
            count: 0
        }, {
            title: '个人',
            name: 'home_self_frm',
            is_active: false,
            normal: '../image/index/menu_icon_4.png',
            selected: '../image/index/menu_icon_4_action.png',
            categoryid: 0,
            type: 0
        }]
    },
    methods: {
        get_read_state: function() {
            var that = this;
            var options = {};
            options.action = "gettotalundreadpushmsgcount";
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    that.footers[2].count = data.count;
                    that.footers[1].count = data.servicecount;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        open_menu: function(item) {
            var that = this;
            for (var i = 0; i < that.footers.length; i++) {
                that.footers[i].is_active = false;
            }
            item.is_active = true;
            var frameH = api.winHeight - 50;
            api.openFrame({
                name: item.name,
                url: '../html/' + item.name + '.html',
                bounces: false,
                params: {
                    servicetype: item.type
                },
                rect: {
                    x: 0,
                    y: 0,
                    w: 'auto',
                    h: frameH
                }
            })
            if (item.name == 'customerservice_win') {
                api.sendEvent({
                    name: 'doopenservicewin',
                });
            }
            if (item.name == 'home_news_win') {
                api.sendEvent({
                    name: 'doopenhomenewswin',
                });
            }
        },
        set_status_bar: function() {
            var that = this;
            api.setStatusBarStyle({
                style: 'dark',
                color: '#fff'
            });
        }
    }
});
apiready = function() {
    api.parseTapmode();
    setTimeout(function() {
        app.set_status_bar();
    }, 5000)
    var delay = 100;
    if (api.systemType != 'ios') {
        delay = 100;
    }
    var body_h = $api.offset($api.dom('body')).h;
    ns = window.Foresight.Util;
    NVTabBar = api.require('NVTabBar');
    app.get_read_state();
    app.open_menu(app.footers[0]);
    api.addEventListener({
        name: 'ajpushnotifyalert'
    }, function(ret, err) {
        setTimeout(function() {
            ns.openWin('home_news_frm', '任务消息', {
                ischeckpage: true,
            });
            api.sendEvent({
                name: 'ajpushnotupdate',
            });
        }, 500);
    });
    api.addEventListener({
        name: 'reloadunreadmsgcount'
    }, function(ret, err) {
        setTimeout(function() {
            app.get_read_state();
        }, 500);
    });
}
